/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 周斌
 * Date: 2024-06-24
 * Time: 16:05
 */
//day14 力扣11 贪心算法练习 双指针+贪心
public class Main {
    public int maxArea(int[] height) {
        int length = height.length;
        int left = 0;
        int right = length-1;
        int Area = 0;
        int maxArea = 0;
        while(left < right) {
            //比较height[left]与height[right]的大小,较小的指针则移动（体现了小小的贪心）
            if (height[left] <= height[right] ) {
                int h = right - left;
                 Area = height[left] * h;
                maxArea = Math.max(maxArea,Area);
                left++;
            } else {
                int h = right - left;
                 Area = height[right] * h;
                 maxArea = Math.max(maxArea,Area);
                right--;
            }
        }
        return maxArea;
    }
    public static void main(String[] args) {
        Main main = new Main();
        int[] array = {1,8,6,2,5,4,8,3,7};
        int[] array1 = {2,3,4,5,18,17,6};
        System.out.println(main.maxArea(array));
        System.out.println(main.maxArea(array1));
    }
}
